<?php
/**
 * This file is form http://findcat.cn
 *
 * @link     https://findcat.cn
 * @email    1476982312@qq.com
 */
namespace App\Http\Controllers\Home;

use App\Models\User;
use App\Http\Controllers\Controller;

class ReaderController extends Controller
{
    /**
     * 金牌用户排序.
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        $users = User::query()->withCount('comment')->orderBy('comment_count', 'desc')->limit(9)->get();

        $i     = 0;
        foreach ($users as $key => $val) {
            $i++;

            switch ($key + 1) {
                case 1:
                    $users[$key]['famous_user'] = '金牌用户';
                    break;
                case 2:
                    $users[$key]['famous_user'] = '银牌用户';
                    break;
                case 3:
                    $users[$key]['famous_user'] = '铜牌用户';
                    break;
                default:
                    $users[$key]['famous_user'] = '普通用户';
                    break;
            }
        }

        $data = [
            'users' => $users,
        ];

        return view('home.readers', $data);
    }
}
